package com.gking.processHarvest.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gking.processHarvest.common.Res;
import com.gking.processHarvest.entity.Project;
import com.gking.processHarvest.service.Project.ProjectService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/project")
public class ProjectController {

    @Autowired
    private ProjectService projectService;

    /**
     * 创建项目
     *
     * @param project
     * @return
     */
    @PostMapping("/create")
    public Res<String> createProject(@RequestBody Project project) {
        log.warn("传入创建的项目信息为：{}", project);
        return projectService.createProject(project.getTitle(), project.getDescription());
    }


    /**
     * 删除项目
     *
     * @param projectId
     * @return
     */
    @DeleteMapping("/delete/{projectId}")
    public Res<String> deleteProject(@PathVariable String projectId) {
        log.warn("要删除的项目 id : {}", projectId);
        return projectService.deleteProject(projectId);
    }


    /**
     * 修改项目信息
     *
     * @param project
     * @return
     */
    @PutMapping("/update")
    public Res<String> updateInfo(@RequestBody Project project) {
        log.warn("修改的信息为 : {}", project);
        return projectService.updateInfo(project.getId(), project.getTitle(), project.getDescription());
    }

    /**
     * 分页查询项目
     *
     * @param page     分页页码
     * @param pageSize 分页大小
     * @return s
     */
    @GetMapping("/projectList")
    public Res<Page> getProjectList(Integer page, Integer pageSize) {
        log.warn("要查询的分页信息 page为 {}， pageSize {}", page, pageSize);
        if (page == null) page = 1;
        if (pageSize == null) pageSize = 12;

        return projectService.getProjectList(page, pageSize);
    }

}
